package com.wing.product.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.product.dao.ProductTypeProcessDao;
import com.wing.product.model.entity.ProductTypeProcess;
import com.wing.product.model.request.ProductTypeProcessForm;
import com.wing.product.model.response.ProductTypeProcessVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 产品类型-工序中间表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ProductTypeProcessServiceImpl extends ServiceImpl<ProductTypeProcessDao, ProductTypeProcess> implements ProductTypeProcessService {

    @Override
    public int add(ProductTypeProcessForm productTypeProcessForm) {
        int i = 0;
        //校验
        for (Long processId : productTypeProcessForm.getProcessIds()) {
            ProductTypeProcess productTypeProcess =new ProductTypeProcess();
            productTypeProcess.setProcessId(processId);
            productTypeProcess.setProductTypeId(productTypeProcessForm.getProductTypeId());
            baseMapper.insert(productTypeProcess);
            i++;
        }
        return i;
    }

    @Override
    public List<ProductTypeProcessVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<ProductTypeProcessVO> pageList4app(Page page, Map<String, Object> params) {
        List<ProductTypeProcessVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public ProductTypeProcessVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }
}
